package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.service.UploadService;
import com.itheima.utils.AliOssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.UUID;

@RestController
public class UploadController {
    @PostMapping("/upload")
    public Result<?> uploadFile(MultipartFile file) throws Exception{
        String orginalFilename = file.getOriginalFilename();
        String filename = UUID.randomUUID()+ orginalFilename.substring(orginalFilename.lastIndexOf("."));
        String url = AliOssUtil.uploadFile(filename, file.getInputStream());
        return Result.success(url);
    }
}
